package controller;

import gui.HomeUI;
import gui.IndexUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import api.UserGetter;

public class BtnLoginAction implements ActionListener {

	private IndexUI gui;

	public BtnLoginAction(IndexUI gui) {
		this.gui = gui;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		boolean check = UserGetter.checkLogin(gui.getTf_username().getText(),
				new String(gui.getTf_password().getPassword()));
		if (check) {
			gui.setVisible(false);
			HomeUI.getInstance().setVisible(true);
		} else {
			JOptionPane.showMessageDialog(gui,
					"Your username or password is incorrect", "Message",
					JOptionPane.ERROR_MESSAGE);
		}
	}

}
